"""仅生成 hit.wav（无需 pygame）。"""
import os, math, wave, struct
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ASSETS_DIR = os.path.join(BASE, 'assets')
os.makedirs(ASSETS_DIR, exist_ok=True)

path = os.path.join(ASSETS_DIR, 'hit.wav')
print('writing', path)

def generate_hit_wav(path, duration_s=0.18, freq=880.0, volume=0.5, samplerate=44100):
    n_samples = int(samplerate * duration_s)
    with wave.open(path, 'w') as wf:
        wf.setnchannels(1)
        wf.setsampwidth(2)  # 16-bit
        wf.setframerate(samplerate)
        for i in range(n_samples):
            t = i / samplerate
            env = (1 - math.exp(-20 * t)) * math.exp(-6 * t)
            sample = int(volume * 32767.0 * env * math.sin(2 * math.pi * freq * t))
            wf.writeframes(struct.pack('<h', sample))

if __name__ == '__main__':
    generate_hit_wav(path)
    print('done')
